class Employee {
    Integer employeeId//
    String firstName//
    String lastName//
    Date dob//
    String title//
    Double salary//
    String email//
    String street//
    String phoneNumber
    String city
    Integer zipCode
    Area hiredBy
    Integer mode =1 //default mode is sandbox mode and 0 is budget mode
    Access access
    
   // Boolean admin//
    Float percentageWork = 100.0//

    static hasMany = [loaner : Bwhoa, worksIn : Whoa]

    static Integer workingHoursBellow = 1732
    static Integer workingHoursOver = 1700

    static Integer fortyYears = 40

    static transients = ['workingHoursPerYear']
    static belongsTo = Area
    
    static constraints = {
        //personal informations
        firstName(size:2..20,matches:"[a-öA-Ö ]+",blank:false)
        lastName(size:2..20,matches:"[a-öA-Ö ]+",blank:false)
        street(size:2..20,matches:"[a-öA-Ö0-9 ]+",blank:false)
        city(size:2..20,matches:"[a-öA-Ö ]+",blank:false)
        zipCode(min:10000,max:99999,blank:false)
        dob(max:new Date())
        email(size:5..50,email:true,blank:false)
        hiredBy(nullable:true)
        access(nullable:true)
        //professional informations
        title(size:1..20,blank:false)
        salary(matches:"[0-9., ]+",min:0d,max:999999d,blank:false)
        percentageWork(min:0f,max:100f)
        employeeId(blank:false)
    }
   
    Boolean isWorkingOverTime(){
        boolean overTime = false
        if( percentageWork > 100)
        {
            overTime = true
        }
        return overTime

    }
    Integer getWorkingHoursPerYear() {
        Date today = new Date();
        // when create new date, date.getYear returns the current year minus 1900. Crazy Java !
        if (dob != null && ((today.getYear()+1900) - dob.getYear()) >= fortyYears) {
            return percentageWork * workingHoursOver / 100
        } else {
            return percentageWork * workingHoursBellow / 100
        }
    }

    public List listOfProjects(){ // "List" = What will be returned
        Date d = new Date();
        ArrayList l =  new ArrayList();
        for(Whoa a in worksIn){         //for every whoa in the whoalist(?)
            if(a?.year == d.getYear()){ //if the year for the project that the employee works in is equal to this year (2009) add to the list l
                l.add(a);
            }
        }
        println(l)  //want to see this!
        return l;
    }

    Integer actualWorkingHoursPerYear() {      //calculate the total ammout of worked hours for one employee in all project for one year
        List l = this.listOfProjects()         //call the function in this class to get the list with whoa of this year
        int sum = 0
        for (Whoa i in l) {
            sum = i.hours+sum
        }
        return sum
    }
    
    String toString(){"${this.firstName} ${this.lastName} "}


}
